import { reqGetDetailList,reqAddOrUpdateShopCart } from "@/api"
const state ={
    detailList:{}
}

const actions = {
   async getDetailList({commit},skuId){
       let result = await reqGetDetailList(skuId);
       console.log(result.data)
       if(result.code == 200){
           commit('GETDETAILLIST',result.data)
       }
   },
   async addShopCart({commit},{skuId,skuNum}){
       let result = await reqAddOrUpdateShopCart(skuId,skuNum);
       if(result.code == 200){
           console.log(0)
            return 'ok'
       }else{
           return Promise.reject(new Error('faile'));
       }
   }
}
const mutations={
    GETDETAILLIST(state,detailList){
            state.detailList = detailList
    }
}
const getters={
    categoryView(state){
        return state.detailList.categoryView||{}
    },
    spuSaleAttrList(state){
        return state.detailList.spuSaleAttrList
    },
    skuInfo(state){
        return state.detailList.skuInfo||{}
    }
}
export default {
    state,
    actions,
    mutations,
    getters
}